package booksys.books;


import booksys.common.CurrentUser;
import booksys.common.Result;
import booksys.common.Utils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@WebServlet({
        "/books",
})
public class BooksAPI extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        request.setCharacterEncoding("UTF-8");
        BooksService booksService = new BooksService();
        String path = request.getServletPath();
        CurrentUser currentUser = (CurrentUser) request.getSession().getAttribute(CurrentUser.SESSION_ATTR_NAME);


    }
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("UTF-8");

        BooksDto booksDto = new BooksDto();

        booksDto.setB_name(req.getParameter("b_name"));
        booksDto.setB_id(req.getParameter("b_id"));
        booksDto.setB_writer(req.getParameter("b_writer"));
        booksDto.setB_publish(req.getParameter("b_publish"));
        booksDto.setB_keywords(req.getParameter("b_keywords"));

        //创建业务模型对象（服务对象/Service对象），通过业务对象执行业务方法
        CurrentUser currentUser = (CurrentUser) req.getSession().getAttribute(CurrentUser.SESSION_ATTR_NAME);
        BooksService booksService = new BooksService();
        Map<String,Object> page = booksService.getBooksList(currentUser.getUserId(),booksDto);

        //通过视图生成json
        //Utils.outJson(response, bobList);
        Utils.outResult(resp, Result.success(page));

    }
}
